﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="surveyList.ascx.cs"
    Inherits="Zebra.Umbraco.Marcos.Survey.surveyList" %>
<form id="Form2" runat="server" style="width: 620px">   
<div id="foobar" style="padding: 15px; display: none">
    <p>
        调查名称<br />
        <asp:TextBox ID="txtSurveyName" Columns="50" runat="server" ClientIDMode="Static"></asp:TextBox><span
            id="emptyStar" style="visibility: hidden">*</span>
    </p>
    <p>
        类别<br />
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Selected="True" Value="1">不知道啦</asp:ListItem>
            <asp:ListItem Value="2">等你们决定啦</asp:ListItem>
            <asp:ListItem Value="3">还是没有类别啦</asp:ListItem>
        </asp:DropDownList>
    </p>
    <p class="no-border">
        <asp:Button ID="Button1" OnClientClick=" return test();" CssClass="button" runat="server"
            Text="创建" OnClick="Button1_Click" Style="height: 26px" ClientIDMode="Static" />
        <div id="foobar2" style="visibility: hidden">
            <span style="color: Red" id="errorText">已存在调查</span></div>
    </p>
</div>
<p>
    <input id="open-custom-dialog" class="button" type="button" value="新建调查" />
</p>
<p>
    <asp:GridView CssClass="MailListTable" ID="GridView1" runat="server" AutoGenerateColumns="False"
        AllowPaging="True" OnRowCommand="GridView1_RowCommand">
        <Columns>
            <asp:HyperLinkField HeaderStyle-Width="200" HeaderText="名称" 
                DataTextField="Name" DataNavigateUrlFields="surveyID"  DataNavigateUrlFormatString="/survey/{0}/Edit.aspx">
<HeaderStyle Width="200px"></HeaderStyle>
            </asp:HyperLinkField>
            <asp:BoundField HeaderStyle-Width="50" HeaderText="创建日期" DataFormatString="{0:yyyy/MM/dd}"
                DataField="RowCreatedOn" >
<HeaderStyle Width="50px"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField HeaderStyle-Width="200" HeaderText="收集器" DataField="Name" >
<HeaderStyle Width="200px"></HeaderStyle>
            </asp:BoundField>
            <asp:TemplateField HeaderStyle-Width="60" HeaderText="分析">
<HeaderStyle Width="60px"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderStyle-Width="60" HeaderText="操作">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%# Eval("surveyID")  %>'
                        CommandName="Remove" OnClientClick="return confirm('是否确定要删除此调查');">删除</asp:LinkButton>
                </ItemTemplate>

<HeaderStyle Width="60px"></HeaderStyle>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:Label ID="lbNoRecord" runat="server" Text="尚未创建调查" Visible="false"></asp:Label>
</p>
</form>
<script type="text/javascript">
    (function ($) {
        $(function () {
            $("#open-custom-dialog").click(function () {
                $.dialog({
                    title: "新建调查",
                    btns: ["cancel"],
                    defaultBtn: "cancel",
                    contentBtnHelp: true,
                    className: "custom-dialog",
                    content: $("#foobar"),
                    father: "#Form2"
                })
            });
        });
    })(jQuery);
    var testVal = false;
    var testText;
    var validationDone = false;
    function test() {
        if ($("#txtSurveyName").val().trim() == "") {
            $("#emptyStar").css("visibility", "");
            return false;
        } else {
            $("#emptyStar").css("visibility", "hidden");
        }
        if (!validationDone) {
            testText = $("#txtSurveyName").val()
            var rr = '/survey/check/' + testText;
            $.ajax({
                url: rr,
                type: 'GET',
                error: function () {
                    validationDone = true;
                    testVal = true;
                    $("#Button1").click();

                },
                success: function (xml) {
                    validationDone = true;
                    $("#foobar2").css("visibility", "");
                    testVal = false;

                }
            });
            return false;
        } else {
            if (testText == $("#txtSurveyName").val()) {
                return testVal;
            } else {
                validationDone = false;
                return test();
            }
        }
    }
     
</script>
